package com.mengniu.commerce.sync.controller;


import com.alibaba.fastjson.JSONObject;
import com.mengniu.commerce.common.core.domain.R;
import com.mengniu.commerce.common.core.web.controller.BaseController;
import com.mengniu.commerce.common.log.annotation.Log;
import com.mengniu.commerce.common.log.enums.BusinessType;
import com.mengniu.commerce.sync.api.base.MnResult;
import com.mengniu.commerce.sync.api.domain.CreateItemModel;
import com.mengniu.commerce.sync.api.domain.ModifyItemModel;
import com.mengniu.commerce.sync.service.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品创建controller
 *
 * @author zfw
 */
@RestController
@RequestMapping("/item")
@Slf4j
public class ItemController extends BaseController
{
       @Autowired
    private ItemService itemService;



    @Log(title = "商品创建管理", businessType = BusinessType.INSERT)
    @PostMapping("/createItem")
    public R createItem(@RequestBody List<CreateItemModel> createItemModelList, String source)
    {
        log.info("商品创建参数为:{},{}", JSONObject.toJSONString(createItemModelList),source);
        //todo RetryDTO
        return itemService.createItem(createItemModelList,null);

    }

    @Log(title = "商品修改管理", businessType = BusinessType.INSERT)
    @PostMapping("/modify")
    public R modify(@RequestBody ModifyItemModel modifyItemModel, String source)
    {
        log.info("商品创建参数为:{},{}", JSONObject.toJSONString(modifyItemModel),source);
        //todo RetryDTO
        return itemService.modifyItem(modifyItemModel,null);

    }


}
